const fs = require('fs')
const util = require('util')
const readFile = util.promisify(fs.readFile)


function* read() {
    let data = yield readFile('./a.txt','utf8')
    data = yield readFile(data,'utf8')
    return data
}

// const it = read();
// it.next().value.then(res=>{
//     console.log(res)
// })
function co(it) {
    return new Promise((resolve,reject)=>{
        function next(data) {
            console.log('data=>',data)
            const {value,done} = it.next(data)
            if(done){
                resolve(value)
            }else{
                Promise.resolve(value).then(next,reject)
            }
        }
        next()
    })
}
co(read()).then(res=>{
    console.log(res)
}).catch(err=>{
    console.log(err)
})